home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / ap_mpm.h.z / ap_mpm.h
C/C++ Source or Header  |  2002-07-08  |  9KB  |  201 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef AP_MMN_H
  56. #define AP_MMN_H
  57.  
  58. #include "apr_thread_proc.h"
  59.  
  60. /**
  61.  * @package Multi-Processing Module library
  62.  */
  63.  
  64. /*
  65.     The MPM, "multi-processing model" provides an abstraction of the
  66.     interface with the OS for distributing incoming connections to
  67.     threads/process for processing.  http_main invokes the MPM, and
  68.     the MPM runs until a shutdown/restart has been indicated.
  69.     The MPM calls out to the apache core via the ap_process_connection
  70.     function when a connection arrives.
  71.  
  72.     The MPM may or may not be multithreaded.  In the event that it is
  73.     multithreaded, at any instant it guarantees a 1:1 mapping of threads
  74.     ap_process_connection invocations.  
  75.  
  76.     Note: In the future it will be possible for ap_process_connection
  77.     to return to the MPM prior to finishing the entire connection; and
  78.     the MPM will proceed with asynchronous handling for the connection;
  79.     in the future the MPM may call ap_process_connection again -- but
  80.     does not guarantee it will occur on the same thread as the first call.
  81.  
  82.     The MPM further guarantees that no asynchronous behaviour such as
  83.     longjmps and signals will interfere with the user code that is
  84.     invoked through ap_process_connection.  The MPM may reserve some
  85.     signals for its use (i.e. SIGUSR1), but guarantees that these signals
  86.     are ignored when executing outside the MPM code itself.  (This
  87.     allows broken user code that does not handle EINTR to function
  88.     properly.)
  89.  
  90.     The suggested server restart and stop behaviour will be "graceful".
  91.     However the MPM may choose to terminate processes when the user
  92.     requests a non-graceful restart/stop.  When this occurs, the MPM kills
  93.     all threads with extreme prejudice, and destroys the pchild pool.
  94.     User cleanups registered in the pchild apr_pool_t will be invoked at
  95.     this point.  (This can pose some complications, the user cleanups
  96.     are asynchronous behaviour not unlike longjmp/signal... but if the
  97.     admin is asking for a non-graceful shutdown, how much effort should
  98.     we put into doing it in a nice way?)
  99.  
  100.     unix/posix notes:
  101.     - The MPM does not set a SIGALRM handler, user code may use SIGALRM.
  102.     But the preferred method of handling timeouts is to use the
  103.     timeouts provided by the BUFF abstraction.
  104.     - The proper setting for SIGPIPE is SIG_IGN, if user code changes it
  105.         for any of their own processing, it must be restored to SIG_IGN
  106.     prior to executing or returning to any apache code.
  107.     TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN
  108. */
  109.  
  110. /**
  111.  * This is the function that MPMs must create.  This function is responsible
  112.  * for controlling the parent and child processes.  It will run until a 
  113.  * restart/shutdown is indicated.
  114.  * @param pconf the configuration pool, reset before the config file is read
  115.  * @param plog the log pool, reset after the config file is read
  116.  * @param server_conf the global server config.
  117.  * @return 1 for shutdown 0 otherwise.
  118.  * @deffunc int ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf)
  119.  */
  120. AP_DECLARE(int) ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf);
  121.  
  122. /**
  123.  * predicate indicating if a graceful stop has been requested ...
  124.  * used by the connection loop 
  125.  * @return 1 if a graceful stop has been requested, 0 otherwise
  126.  * @deffunc int ap_graceful_stop_signalled(*void)
  127.  */
  128. AP_DECLARE(int) ap_graceful_stop_signalled(void);
  129.  
  130. /**
  131.  * Spawn a process with privileges that another module has requested
  132.  * @param r The request_rec of the current request
  133.  * @param newproc The resulting process handle.
  134.  * @param progname The program to run 
  135.  * @param const_args the arguments to pass to the new program.  The first 
  136.  *                   one should be the program name.
  137.  * @param env The new environment apr_table_t for the new process.  This 
  138.  *            should be a list of NULL-terminated strings.
  139.  * @param attr the procattr we should use to determine how to create the new
  140.  *         process
  141.  * @param p The pool to use. 
  142.  */
  143. AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
  144.     const request_rec *r,
  145.     apr_proc_t *newproc, 
  146.     const char *progname,
  147.     const char * const *args, 
  148.     const char * const *env,
  149.     apr_procattr_t *attr, 
  150.     apr_pool_t *p);
  151.  
  152. /* Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED        */
  153. #define AP_MPMQ_NOT_SUPPORTED      0  /* This value specifies whether */
  154.                                       /* an MPM is capable of         */
  155.                                       /* threading or forking.        */
  156. #define AP_MPMQ_STATIC             1  /* This value specifies whether */
  157.                                       /* an MPM is using a static #   */
  158.                                       /* threads or daemons.          */
  159. #define AP_MPMQ_DYNAMIC            2  /* This value specifies whether */
  160.                                       /* an MPM is using a dynamic #  */
  161.                                       /* threads or daemons.          */
  162.  
  163. #define AP_MPMQ_MAX_DAEMON_USED       1  /* Max # of daemons used so far */
  164. #define AP_MPMQ_IS_THREADED           2  /* MPM can do threading         */
  165. #define AP_MPMQ_IS_FORKED             3  /* MPM can do forking           */
  166. #define AP_MPMQ_HARD_LIMIT_DAEMONS    4  /* The compiled max # daemons   */
  167. #define AP_MPMQ_HARD_LIMIT_THREADS    5  /* The compiled max # threads   */
  168. #define AP_MPMQ_MAX_THREADS           6  /* # of threads/child by config */
  169. #define AP_MPMQ_MIN_SPARE_DAEMONS     7  /* Min # of spare daemons       */
  170. #define AP_MPMQ_MIN_SPARE_THREADS     8  /* Min # of spare threads       */
  171. #define AP_MPMQ_MAX_SPARE_DAEMONS     9  /* Max # of spare daemons       */
  172. #define AP_MPMQ_MAX_SPARE_THREADS    10  /* Max # of spare threads       */
  173. #define AP_MPMQ_MAX_REQUESTS_DAEMON  11  /* Max # of requests per daemon */
  174. #define AP_MPMQ_MAX_DAEMONS          12  /* Max # of daemons by config   */
  175.  
  176.  
  177. /**
  178.  * Query a property of the current MPM.  
  179.  * @param query_code One of APM_MPMQ_*
  180.  * @param result A location to place the result of the query
  181.  * @return APR_SUCCESS or APR_ENOTIMPL
  182.  * @deffunc int ap_mpm_query(int query_code, int *result)
  183.  */
  184. AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result);
  185.  
  186. /* Defining GPROF when compiling uses the moncontrol() function to
  187.  * disable gprof profiling in the parent, and enable it only for
  188.  * request processing in children (or in one_process mode).  It's
  189.  * absolutely required to get useful gprof results under linux
  190.  * because the profile itimers and such are disabled across a
  191.  * fork().  It's probably useful elsewhere as well.
  192.  */
  193. #ifdef GPROF
  194. extern void moncontrol(int);
  195. #define AP_MONCONTROL(x) moncontrol(x)
  196. #else
  197. #define AP_MONCONTROL(x)
  198. #endif
  199.  
  200. #endif
  201.